<?php 
/**
 * 侧边栏组件、页面模块
 */
if(!defined('EMLOG_ROOT')) {exit('error!');} 
?>
<?php
//widget：blogger
function widget_blogger($title){
	global $CACHE;
	$user_cache = $CACHE->readCache('user');
	$name = $user_cache[1]['mail'] != '' ? "<a href=\"mailto:".$user_cache[1]['mail']."\" class='upp'>".$user_cache[1]['name']."</a>" : $user_cache[1]['name'];?>
    <div class="widget widget_ui_readers">   
    <h3>本周大神</h3>
    <ul><?php 
    $DB = MySql::getInstance();
    $time_side = strtotime('this month', strtotime(date('m/01/y')));
    $sql = 'SELECT count(*) AS comment_nums,poster,mail,url FROM ' . DB_PREFIX . "comment where date > {$time_side}  and poster != '{$userName}' and hide ='n' group by mail order by comment_nums DESC limit 0,12";
    $result = $DB->query($sql);
    while ($row = $DB->fetch_array($result)) {
        $img = '<li><a rel="external nofollow" target="_blank" href="' . $row['url'] . '" title="' . $row['poster'] . ' (赐教' . $row['comment_nums'] . '次)"><img class="avatar avatar-36 photo" height="36" width="36" data-src="' . getGravatar($row['mail']) . '" src="' . TEMPLATE_URL . 'img/avatar-default.png" /></a></li>';
        if ($row['url']) {
            $tmp = '<li><a rel="external nofollow" target="_blank" href="' . $row['url'] . '" title="' . $row['poster'] . ' (赐教' . $row['comment_nums'] . '次)"><img class="avatar avatar-36 photo" height="36" width="36" data-src="' . getGravatar($row['mail']) . '" src="' . TEMPLATE_URL . 'img/avatar-default.png" /></a></li>';
        } else { $tmp = $img;}
        $output .= $tmp;}
    $output = ' ' . $output . ' ';
    echo $output;
    ?>
	</ul></div>
<?php }?>
<?php
//widget：日历
function widget_calendar($title){ ?>
	<div class="widget widget_calendar">
    <h3><?php echo $title;?></h3>
	<div id="calendar">
    </div>
    <script>sendinfo('<?php echo Calendar::url(); ?>','calendar');</script>
    </div>
<?php }?>
<?php
//widget：标签
function widget_tag($title){
	global $CACHE;
	$tag_cache = $CACHE->readCache('tags');?>
<div class="widget widget_ui_tags">      
        <h3><?php echo $title;?></h3>
        <div class="items">
		<?php foreach($tag_cache as $value): ?>
		<a href="<?php echo Url::tag($value['tagurl']); ?>"><?php echo $value['tagname']; ?>(<?php echo $value['usenum']; ?>)</a>
	<?php endforeach; ?>
        </div>
    </div>
<?php }?>
<?php
//widget：分类
function widget_sort($title){
	global $CACHE;
	$sort_cache = $CACHE->readCache('sort'); ?>
<div class="widget widget_links">      
        <h3><?php echo $title;?></h3>
      <ul>
	<?php foreach($sort_cache as $value):if ($value['pid'] != 0) continue;?><li><a target="_blank" href="<?php echo Url::sort($value['sid']); ?>"><?php echo $value['sortname']; ?></a></li><?php endforeach; ?>
</ul>
    </div>
<?php }?>
<?php
//widget：最新微语
function widget_twitter($title){
	global $CACHE; 
	$newtws_cache = $CACHE->readCache('newtw');
	$istwitter = Option::get('istwitter');
	?>
<div class="widget widget_ui_comments">
        <h3><?php echo $title;?></h3>
          <ul> 
    <?php foreach($newtws_cache as $value):?><li>
    <a href="<?php echo BLOG_URL; ?>t" title="<?php echo $value['autohor']; ?>"><?php echo $value['t']; ?><?php echo $img;?><span style="float:right"><?php echo gmdate('Y-n-j G:i', $value['date']); ?></span></a></li>
    <?php endforeach; ?>
    </ul>
</div>
<?php }?>
<?php
//widget：最新评论
function widget_newcomm($title){
	global $CACHE;
	$com_cache = $CACHE->readCache('comment');
	?>
<div class="widget d_comment">
        <h3><?php echo $title;?></h3>
          <ul>
		<?php
		foreach($com_cache as $value):
		$articleUrl = Url::log($value['gid']);
		$url = Url::comment($value['gid'], $value['page'], $value['cid']);
		$db = MySql::getInstance();
		$sql = "SELECT title FROM ".DB_PREFIX."blog WHERE gid=".$value['gid'];
		$ret = $db->query($sql);
		$row = $db->fetch_array($ret);
		$articleTitle = $row['title'];
		$db = MySql::getInstance();
		$sql = "SELECT url FROM ".DB_PREFIX."comment WHERE cid=".$value['cid'];
		$ret = $db->query($sql);
		$row = $db->fetch_array($ret);
		$value['content']=preg_replace("/{smile:(([1-4]?[0-9])|50)}/",'<img class="lazy" src="' . TEMPLATE_URL. 'img/smilies/$1.gif" />',$value['content'])
		?>
		<li>
        <a target="_blank" href="<?php echo $url;?>" title="<?php echo $articleTitle;?>上的评论">
        <img data-src="<?php echo getGravatar($value['mail'], 25);?>" alt="" src="<?php echo TEMPLATE_URL;?>img/avatar-default.png" class="avatar avatar-36 photo" height="36" width"36" style="display: block;">
		<?php echo $value['name'];?>
        <span style="color: #999999;">说道：<br>
		<?php echo $value['content'];?></span></a>
        </li>
		<?php endforeach; ?>
		</ul>
    </div>
<?php }?>
<?php
//widget：最新文章
function widget_newlog($title){
	global $CACHE; 
	$newLogs_cache = $CACHE->readCache('newlog');
	?>
<div class="widget d_postlist" >
        <h3><?php echo $title;?></h3>
          <ul>
	<?php foreach($newLogs_cache as $value): ?> 
    <li>
    <a href="<?php echo Url::log($value['gid']); ?>" title="<?php echo $value['title']; ?>"><?php echo mb_substr($value['title'],0,50,'utf8');?></a></li><?php endforeach; ?>
    </ul>
    </div>
<?php }?>
<?php
//widget：热门文章
function widget_hotlog($title){
	$index_hotlognum = Option::get('index_hotlognum');
	$Log_Model = new Log_Model();
	$randLogs = $Log_Model->getHotLog($index_hotlognum);
	?>
<div class="widget d_postlist">
        <h3><?php echo $title;?></h3>
          <ul>
<?php foreach($randLogs as $value): ?>
<li><a href="<?php echo Url::log($value['gid']); ?>" title="<?php echo $value['title']; ?>"><?php echo mb_substr($value['title'],0,50,'utf8');?></a></li><?php endforeach; ?>
</ul>
</div>
<?php }?>
 <?php
//widget：随机文章
function widget_random_log($title){
	$index_randlognum = Option::get('index_randlognum');
	$Log_Model = new Log_Model();
	$randLogs = $Log_Model->getRandLog($index_randlognum);?>
 <div class="widget d_postlist">
        <h3><?php echo $title;?></h3>
          <ul>
		  <?php foreach($randLogs as $value): ?>
          <li><a href="<?php echo Url::log($value['gid']); ?>" title="<?php echo $value['title']; ?>" rel="bookmark"><?php echo mb_substr($value['title'],0,50,'utf8');?></a></li><?php endforeach; ?>
</ul>
</div>
</div>
<?php }?>
<?php
//widget：搜索
function widget_search($title){ ?>
<div class="widget widget_search">
<h3><?php echo $title;?></h3>
       <div id="searchbar">
        <form style="float: left;color: #999;width: 100%;height: 40;padding: 11px 10px;border-right: 0;font-size: 12px;border-radius: 2px 0 0 2px;outline: 0;" name="keyform" method="get" action="<?php echo BLOG_URL;?>index.php"><input class="search-input" name="keyword" type="text" placeholder="输入关键字搜索" style="width:88%"><button class="search-btn" style="background: #C7C7C7;" type="submit"><span class="icon-search icon-large"></span></button></form>
      </div>
    </div>
<?php } ?>
<?php
//widget：归档
function widget_archive($title){
	global $CACHE; 
	$record_cache = $CACHE->readCache('record');
	?>
<div class="widget widget_archive">
        <h3><?php echo $title;?></h3>
        <ul>
<form><select onchange="window.open(this.options[this.selectedIndex].value,'_self')"><option value="#" selected="selected">请选择归档时间</option><?php foreach ($record_cache as $value) {?>
<option value="<?php echo Url::record($value['date']);?>"><?php echo $value['record'];?>
(<?php echo $value['lognum'];?>)</option><?php }?>
</select></form></ul>
    </div>
<?php } ?>
<?php
//widget：自定义组件
function widget_custom_text($title, $content){?>
<div class="widget widget_ui_textads">
        <h3><?php echo $title;?></h3>
        <div>
	<?php echo $content; ?></div>

	</div>
<?php } ?>
<?php
//widget：链接
function widget_link($title){
	global $CACHE; 
	$link_cache = $CACHE->readCache('link');
    //if (!blog_tool_ishome()) return;#只在首页显示友链去掉双斜杠注释即可
	?>
<div class="widget widget_links" >      
        <h3><?php echo $title;?></h3>
      <ul>
	<?php foreach($link_cache as $value): ?><li><i class="icon-link" style="padding-left: 10px;"></i>
	<a href="<?php echo $value['url']; ?>" title="<?php echo $value['des']; ?>" target="_blank"><?php echo $value['link']; ?></a></li>
	<?php endforeach; ?></ul>
	
    </div>
<?php }?> 
<?php //导航
function blog_navi(){
    global $CACHE;
    $navi_cache = $CACHE->readCache('navi');
    foreach ($navi_cache as $value) {
        if ($value['pid'] != 0) {
            continue; }
        if ($value['url'] == ROLE_ADMIN && (ROLE == ROLE_ADMIN || ROLE == ROLE_WRITER)) {
            continue;}
        $newtab = $value['newtab'] == 'y' ? 'target="_blank"' : '';
        $value['url'] = $value['isdefault'] == 'y' ? BLOG_URL . $value['url'] : trim($value['url'], '/');
        $current_tab = BLOG_URL . trim(Dispatcher::setPath(), '/') == $value['url'] ? 'current' : '';?>
<li class="navto <?php echo $current_tab;?>
"><a href="<?php echo $value['url']; ?>
" <?php echo $newtab;?>
><?php if ($value['naviname'] == '首页') { ?>
<i class="icon-home"></i><?php 
} elseif ($value['naviname'] == '微语') { ?>
<i class="icon-bullhorn"></i><?php 
        } elseif ($value['naviname'] == '相册') {?>
<i class="icon-camera"></i><?php 
        } elseif ($value['naviname'] == '归档') {?>
<i class="icon-list"></i><?php 
        } elseif ($value['naviname'] == '留言' || $value['naviname'] == '留言板') { ?>
<i class="icon-comments"></i><?php 
        } elseif ($value['naviname'] == '读者排行' || $value['naviname'] == '读者墙') {?>
 <i class="icon-book"></i> <?php 
        } elseif ($value['naviname'] == '网盘') {?>
 <i class="icon-hdd"></i><?php 
        } elseif ($value['naviname'] == '登录') {?>
 <i class="icon-user"></i><?php 
        } elseif ($value['naviname'] == '投稿') { ?>
<i class="fa fa-share-alt"></i><?php 
        } elseif ($value['naviname'] == '手机版') { ?>
 <i class="fa fa-mobile"></i><?php 
        } elseif ($value['naviname'] == '登陆') { ?>
 <i class="icon-cog"></i>  <?php 
        } else {?>
 <i class="icon-book"></i><?php 
        }?>
 <?php echo $value['naviname'];?>
</a><?php  if (!empty($value['children'])) { ?>
<ul class="sub-menu"> 
<?php  foreach ($value['children'] as $row) { echo '<li class="navto"><a href="' . Url::sort($row['sid']) . '">' . $row['sortname'] . '</a></li>';}?>
</ul><?php  }if (!empty($value['childnavi'])) { ?>
<ul class="sub-menu"><?php 
            foreach ($value['childnavi'] as $row) {
                $newtab = $row['newtab'] == 'y' ? 'target="_blank"' : '';
                echo '<li class="navto"><a href="' . $row['url'] . '" >' . $row['naviname'] . '</a></li>'; } ?>
</ul><?php } ?>
</li><?php }?>
<li class="navto-theme"><a href="#"><i class="icon-book"></i> 其他<i class="icon-caret-down"></i></a>
	<ul class="sub-menu">
    <li class="navto-d1"><a href="<?php echo BLOG_URL; ?>webtool">工具箱</a></li>
    <li class="navto-d2"><a href="<?php echo BLOG_URL; ?>readers">排行榜</a></li>
    <li class="navto-d3"><a href="<?php echo BLOG_URL;?>?plugin=submit">投稿箱</a></li>
    <li class="navto-d5"><a href="<?php echo BLOG_URL;?>team">个人动态</a></li>
    <li class="navto-d5"><a href="<?php echo BLOG_URL;?>about">关于我哦</a></li>
    </ul></li>
<?php if (ROLE == 'admin' || ROLE == 'writer') {?>
<li class="navto-theme">
<a href="<?php echo BLOG_URL;?>admin"><i class="icon-cog"></i>管理<i class="icon-caret-down"></i></a>
<ul class="sub-menu">
<li class="navto-d7"><a href="<?php echo BLOG_URL;?>admin/comment.php">评论管理</a></li>
<li class="navto-d7"><a href="<?php echo BLOG_URL; ?>admin/write_log.php">发表文章</a></li>
<li class="navto-d7"><a href="<?php echo BLOG_URL;?>admin/?action=logout">退出登陆</a></li></ul></li>
<?php }}?>
<?php
//blog：置顶
function topflg($top, $sortop='n', $sortid=null){
    if(blog_tool_ishome()) {
       echo $top == 'y' ? "<span class=\"new-ico\" />荐</span>" : '';
    } elseif($sortid){
       echo $sortop == 'y' ? "<span class=\"new-ico\" />荐</span>" : '';
    }
}
?>
<?php
//blog：编辑
function editflg($logid,$author){
	$editflg = ROLE == 'admin' || $author == UID ? '<span class="item"><i class="icon-pencil"></i> <a href="'.BLOG_URL.'admin/write_log.php?action=edit&gid='.$logid.'" class="post-edit-link" target="_blank">[编辑]</a></span>' : '';
	echo $editflg;
}
?>
<?php
//blog：分类
function blog_sort($blogid){
	global $CACHE; 
	$log_cache_sort = $CACHE->readCache('logsort');
	?>
	<?php if(!empty($log_cache_sort[$blogid])): ?>
    <a class="cat" href="<?php echo Url::sort($log_cache_sort[$blogid]['id']); ?>"><?php echo $log_cache_sort[$blogid]['name']; ?></a>
    <?php else: ?>
    <a class="cat">暂无分类</a>
	<?php endif;?>
<?php }?>
<?php
//blog：内页分类
function blog_sorts($blogid){
	global $CACHE; 
	$log_cache_sort = $CACHE->readCache('logsort');
	?>
	<?php if(!empty($log_cache_sort[$blogid])): ?>
    <a href="<?php echo Url::sort($log_cache_sort[$blogid]['id']); ?>"><?php echo $log_cache_sort[$blogid]['name']; ?></a>
    <?php else: ?>
    <a>暂无分类</a>
	<?php endif;?>
<?php }?>
<?php
//blog：日志标签
function blog_tag($blogid){
	global $CACHE;
	$log_cache_tags = $CACHE->readCache('logtags');
	if (!empty($log_cache_tags[$blogid])){
		$tag = '标签：';
		foreach ($log_cache_tags[$blogid] as $key=>$value){
			$tag .= "<a href=\"".Url::tag($value['tagurl'])."\" class=\"tag".$key."\" rel=\"tag\">".$value['tagname'].'</a>';
		}
		echo $tag;
	}else {
		echo '<div class="j_warn">本文文暂无标签</div>';
	}
}
?>
<?php
//blog：文章作者
function blog_author($uid){
	global $CACHE;
	$user_cache = $CACHE->readCache('user');
	$author = $user_cache[$uid]['name'];
	$mail = $user_cache[$uid]['mail'];
	$des = $user_cache[$uid]['des'];
	$title = !empty($mail) || !empty($des) ? "title=\"$des $mail\"" : '';
	echo '<a href="'.Url::author($uid)."\" class='upp' $title>$author</a>";
}
?>
<?php
//blog：相邻文章
function neighbor_log($neighborLog){
	extract($neighborLog);?>
    <span class="article-nav-prev">
	<?php if($prevLog):?>
    <a>【上一篇】</a><br>
	<a href="<?php echo Url::log($prevLog['gid']) ?>" title="<?php echo $prevLog['title'];?>"><?php echo $prevLog['title'];?></a>
    <?php else: ?>
    <a>【上一篇】</a><br>
    <a title="没错这就是本分类第一篇文章">这就是第一篇了</a>
	<?php endif;?></span>
    <span class="article-nav-next">
	<?php if($nextLog):?>
    <a>【下一篇】</a><br>
	<a href="<?php echo Url::log($nextLog['gid']) ?>" title="<?php echo $nextLog['title'];?>"><?php echo $nextLog['title'];?></a>
    <?php else: ?>
    <a>【下一篇】</a><br>
    <a title="没错这就是本分类最后一篇文章">这就是最后一篇了</a>
	<?php endif;?></span>
    
<?php }?>
<?php  //评论
function blog_comments($comments,$comnum,$params){
		extract($comments);
		if($commentStacks): ?>
        <div id="liststitle">
        <a name="comments"></a>
        <div class="title"><h3>网友评论<b>(<?php echo $comnum;?>)</b></h3>
        </div></div>
		<?php endif;?>
        <ol class="commentlist">
		<?php $isGravatar = Option::get('isgravatar');
		$comnum = count($comments);
		foreach($comments as $value){if($value['pid'] != 0){$comnum--;}
		}$page = isset($params[5])?intval($params[5]):1;
		$i= $comnum - ($page - 1)*Option::get('comment_pnum');
		foreach($commentStacks as $cid):$comment = $comments[$cid];
		$comment['content'] = preg_replace("/{smile:(([1-4]?[0-9])|50)}/",'<img src="' . TEMPLATE_URL. 'img/smilies/$1.gif" />',$comment['content']);
		$comment['poster'] = $comment['url'] ? '<a href="'.$comment['url'].'" target="_blank" class="ds-user-name ds-highlight" rel="nofollow">'.$comment['poster'].'</a>' : $comment['poster'];?>
        <li class="comment even thread-even depth-1" id="<?php echo $comment['cid'];?>">
		<a name="<?php echo $comment['cid'];?>"></a>
        <span class="comt-f">
		<?php if ($i == 1){ echo "沙发#";}
				elseif ($i == 2){echo "椅子#";}
				elseif ($i == 3){ echo "板凳#";}
				elseif ($i == 4){ echo "地板#";}				
				else{ echo "#$i";}?></span>
		<div class="comt-avatar"><?php if($isGravatar == 'y'): ?>
        <img class="avatar avatar-50 photo" height="50" width="50" style="display: block;" src="<?php echo TEMPLATE_URL;?>img/avatar-default.png" alt="avatar" data-src="<?php echo getGravatar($comment['mail']);?>"><?php endif;?></div>
        <div class="comt-main" id="div-comment-<?php echo $comment['cid'];?>">
        <p><?php echo $comment['content'];?></p>
		<div class="comt-meta">
        <span class="comt-author"><?php echo $comment['poster'];?> <?php $mail_str="\"".strip_tags($comment['mail'])."\"";echo_levels($mail_str,"\"".$comment['url']."\"");?> <a title="<?php echo convertip($comment['ip']);?>"> 
        <img src="<?php echo TEMPLATE_URL;?>img/ip.png" alt="" width="16" height="16"></a> <?php if(function_exists('display_useragent')){display_useragent($comment['cid']);} ?></span>
		<?php echo $comment['date'];?> 
        <a class="comment-reply-link" href="#comment-<?php echo $comment['cid'];?>" onclick="commentReply(<?php echo $comment['cid'];?>,this)" >回复</a>
        </div></div>
		<?php blog_comments_children($comments, $comment['children']);?></li>
		<?php $i--;endforeach;?>
        </ol>
		<?php if($commentPageUrl) {?>
        <div class="pagenav"><?php echo $commentPageUrl;?></div>
	<?php } ?>
<?php }?>
<?php function blog_comments_children($comments, $children){$isGravatar = Option::get('isgravatar');
		foreach($children as $child) {$comment = $comments[$child];
		$comment['content'] = preg_replace("/{smile:(([1-4]?[0-9])|50)}/",'<img src="' . TEMPLATE_URL. 'img/smilies/$1.gif" /></a>',$comment['content']);
		$comment['poster'] = $comment['url'] ? '<a href="'.$comment['url'].'" target="_blank" class="ds-user-name ds-highlight" rel="nofollow">'.$comment['poster'].'</a>' : $comment['poster'];?>
        <ul class="children"> 
        <li class="comment even thread-even depth-1" id="<?php echo $comment['cid'];?>">
		<a name="<?php echo $comment['cid'];?>"></a>
		<div class="comt-avatar"><?php if($isGravatar == 'y'): ?>
        <img class="avatar avatar-50 photo" height="50" width="50" style="display: block;" src="<?php echo TEMPLATE_URL;?>img/avatar-default.png" alt="avatar" data-src="<?php echo getGravatar($comment['mail']);?>"><?php endif;?></div>
        <div class="comt-main" id="div-comment-<?php echo $comment['cid'];?>">
        <p><?php echo $comment['content'];?></p>
		<div class="comt-meta">
        <span class="comt-author"><?php echo $comment['poster'];?> <?php $mail_str="\"".strip_tags($comment['mail'])."\"";echo_levels($mail_str,"\"".$comment['url']."\"");?> <a title="<?php echo convertip($comment['ip']);?>"> 
        <img src="<?php echo TEMPLATE_URL;?>img/ip.png" alt="" width="16" height="16"></a> <?php if(function_exists('display_useragent')){display_useragent($comment['cid']);} ?></span>
		<?php echo $comment['date'];?>
        <?php if($comment['level'] < 3): ?> 
        <a class="comment-reply-link" href="#comment-<?php echo $comment['cid'];?>" onclick="commentReply(<?php echo $comment['cid'];?>,this)" >回复</a><?php endif ;?>
        </div></div>
		<?php blog_comments_children($comments, $comment['children']);?>
        </li>
        </ul>
<!-- .children -->
<?php } ?>
<?php }?>
<?php
//blog：发表评论表单
function blog_comments_post($logid,$ckname,$ckmail,$ckurl,$verifyCode,$allow_remark){
	if($allow_remark == 'y'):
	 ?>
<div id="comment-place">
<div class="comment-post" id="comment-post"><div class="commenttitle" style="margin-bottom: 15px;"><div class="title"><h3>评论 <?php 
        if (ROLE == 'admin' || ROLE == 'writer') { 
		} else {?>
<a onclick="show_div()"><small>- 帐号管理</small></a><?php }?>
</h3></div></div>
<script type="text/javascript" language="javascript">
function show_div(){var obj_div=document.getElementById("comment-author-info");
obj_div.style.display=(obj_div.style.display=='none')?'block':'none';
}</script>
<form action="<?php echo BLOG_URL; ?>index.php?action=addcom" method="post" id="commentform">
<input type="hidden" name="gid" value="<?php echo $logid; ?>" />
		<div class="comt">
			<div class="comt-title">
<img data-src="<?php echo getGravatar($ckmail, 80); ?>" src="<?php echo TEMPLATE_URL;?>img/avatar-default.png"class="avatar avatar-50 photo avatar-default" height="50" width="50">
<a id="cancel-reply" href"javascript:void(0);" onclick="cancelReply()" style="display:none">取消</a>
			</div>
			<div class="comt-box">
				<textarea placeholder="你的评论可以一针见血" class="input-block-level comt-area" name="comment" id="comment" cols="100%" rows="3" tabindex="1" onkeydown="if(event.ctrlKey&amp;&amp;event.keyCode==13){document.getElementById('submit').click();return false};"></textarea>
				<div class="comt-ctrl">
					<div class="comt-tips"><?php echo $verifyCode; ?>
</div>
					<button type="submit" name="submit" id="submit" tabindex="5">提交评论</button>
                    <input type="hidden" name="pid" id="comment-pid" value="0" size="22" tabindex="1"/>
					<!--<span data-type="comment-insert-smilie" class="muted comt-smilie"><i class="icon-thumbs-up icon12"></i> 表情</span>-->
				</div>
			</div>
            <?php if(ROLE == ROLE_VISITOR): ?>
<div class="comt-comterinfo" id="comment-author-info" <?php if($ckname != '') echo ' style="display:none;"'; ?>>
						<ul>
							<li class="form-inline">
                            <label class="hide" for="author">昵称</label><input class="ipt" type="text" name="comname" id="author" value="<?php echo $ckname;?>" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline">
                            <label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="commail" id="email" value="<?php echo $ckmail;?>" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline">
                            <label class="hide" for="url">网址</label><input class="ipt" type="text" name="comurl" id="url" value="<?php echo $ckurl;?>" tabindex="4" placeholder="网址"><span class="text-muted">网址</span></li>
						</ul>
					</div><?php endif;?>
		</div>
	</form></div></div>
    <?php endif;?>
    <?php }?>

<?php
//blog-tool:判断是否是首页
function blog_tool_ishome(){
    if (BLOG_URL . trim(Dispatcher::setPath(), '/') == BLOG_URL){
        return true;
    } else {
        return FALSE;
    }
}
?>
<?php
//获取附件第一张图片
function getThumbnail($blogid){
    $db = MySql::getInstance();
    $sql = "SELECT * FROM ".DB_PREFIX."attachment WHERE blogid=".$blogid." AND (`filepath` LIKE '%jpg' OR `filepath` LIKE '%gif' OR `filepath` LIKE '%png') ORDER BY `aid` ASC LIMIT 0,1";
    //die($sql);
    $imgs = $db->query($sql);
    $img_path = "";
    while($row = $db->fetch_array($imgs)){
         $img_path .= BLOG_URL.substr($row['filepath'],3,strlen($row['filepath']));
    }
    return $img_path;
}
?>
<?php
function handlearticledes($des) {
	$str = preg_replace("/(<\/?)(\w+)([^>]*>)/e",'',$des);
	$str = preg_replace("/阅读全文&gt;&gt;/",'',$str);
	$str = strip_tags($str,""); 
    $str = ereg_replace("\t","",$str); 
    $str = ereg_replace("\r\n","",$str); 
    $str = ereg_replace("\r","",$str); 
    $str = ereg_replace("\n","",$str); 
    $str = ereg_replace(" "," ",$str); 
	return mb_substr($str,0,200,'utf8');
}
?>
<?php
function index_t(){
	$t = MySql::getInstance();
	?>
	<?php
	$sql = "SELECT id,content,img,author,date,replynum FROM ".DB_PREFIX."twitter ORDER BY `date` DESC LIMIT 3";
	$list = $t->query($sql);
	while($row = $t->fetch_array($list)){
	?><li><i class="icon-bulletin"></i>
<a href="<?php echo BLOG_URL; ?>t" rel="bookmark"><?php echo $row['content'];?></a></li>
<?php }?>
<?php } ?>
<?php
function timer_start() {
  global $timestart;
  $mtime = explode( ' ', microtime() );
  $timestart = $mtime[1] + $mtime[0];
  return true;
}
timer_start();
function timer_stop( $display = 0, $precision = 3 ) {
  global $timestart, $timeend;
  $mtime = explode( ' ', microtime() );
  $timeend = $mtime[1] + $mtime[0];
  $timetotal = $timeend - $timestart;
  $r = number_format( $timetotal, $precision );
  if ( $display )
    echo $r;
  return $r;
}
?>
<?php
//文章关键词
function log_key_words($blogid){
	global $CACHE;
	$log_cache_tags = $CACHE->readCache('logtags');
	if (!empty($log_cache_tags[$blogid])){
		$tag = '';
		foreach ($log_cache_tags[$blogid] as $value){
			$tag .="".$value['tagname'].',';
		}
		echo substr($tag,0,-1);
	}
}
?>
<?php
//随便看看
function sbkk_logs() {
$db = MySql::getInstance();
$sql = "SELECT gid FROM ".DB_PREFIX."blog WHERE type='blog' and hide='n' ORDER BY rand() LIMIT 0,1";
$sbkk_logs_list = $db->query($sql);
while($row = $db->fetch_array($sbkk_logs_list)){ 
echo Url::log($row['gid']);}
}?>
<?php
//comment：输出评论人等级
function echo_levels($comment_author_email,$comment_author_url){
  $DB = MySql::getInstance();
  global $CACHE;$user_cache = $CACHE->readCache('user'); 
  $adminEmail = '"'.$user_cache[1]['mail'].'"';
  if($comment_author_email==$adminEmail)
  {
    echo '<a class="vip" href="mailto:'.$user_cache[1]['mail'].'" title="管理员认证"></a>';
  }
  $sql = "SELECT cid as author_count,mail FROM ".DB_PREFIX."comment WHERE mail != '' and mail = $comment_author_email and hide ='n'";
  $res = $DB->query($sql);
  $author_count = mysql_num_rows($res);
   if($author_count>=2 && $author_count<10 && $comment_author_email!=$adminEmail)
    echo '<a class="vip1" title="路过酱油 LV.1"></a>';
  else if($author_count>=10 && $author_count<20 && $comment_author_email!=$adminEmail)
    echo '<a class="vip2" title="偶尔光临 LV.2"></a>';
  else if($author_count>=20 && $author_count<40 && $comment_author_email!=$adminEmail)
    echo '<a class="vip3" title="常驻人口 LV.3"></a>';
  else if($author_count>=40 && $author_count<80 && $comment_author_email!=$adminEmail)
    echo '<a class="vip4" title="以博为家 LV.4"></a>';
  else if($author_count>=80 &&$author_count<160 && $comment_author_email!=$adminEmail)
    echo '<a class="vip5" title="情牵小博 LV.5"></a>';
  else if($author_count>=160 && $author_coun<320 && $comment_author_email!=$adminEmail)
    echo '<a class="vip6" title="为博终老 LV.6"></a>';
  else if($author_count>=320 && $author_coun<10000 && $comment_author_email!=$adminEmail)
    echo '<a class="vip7" title="三世情牵 LV.7"></a>';
}
?>
<?php function related_logs($logData = array())
{
    $related_log_type = 'sort';
    $related_log_sort = 'rand';
    $related_log_num = '8';
    $related_inrss = 'y';
    global $value;
    $DB = MySql::getInstance();
    $CACHE = Cache::getInstance();
    extract($logData);
    if ($value) {
        $logid = $value['id'];
        $sortid = $value['sortid'];
        global $abstract;
    }
    $sql = 'SELECT gid,title FROM ' . DB_PREFIX . 'blog WHERE hide=\'n\' AND type=\'blog\'';
    if ($related_log_type == 'tag') {
        $log_cache_tags = $CACHE->readCache('logtags');
        $Tag_Model = new Tag_Model();
        $related_log_id_str = '0';
        foreach ($log_cache_tags[$logid] as $key => $val) {
            $related_log_id_str .= ',' . $Tag_Model->getTagByName($val['tagname']);
        }
        $sql .= " AND gid!={$logid} AND gid IN ({$related_log_id_str})";
    } else {
        $sql .= " AND gid!={$logid} AND sortid={$sortid}";
    }
    switch ($related_log_sort) {
        case 'views_desc':
            $sql .= ' ORDER BY views DESC';
            break;
        case 'views_asc':
            $sql .= ' ORDER BY views ASC';
            break;
        case 'comnum_desc':
            $sql .= ' ORDER BY comnum DESC';
            break;
        case 'comnum_asc':
            $sql .= ' ORDER BY comnum ASC';
            break;
        case 'rand':
            $sql .= ' ORDER BY rand()';
            break;}
    $sql .= " LIMIT 0,{$related_log_num}";
    $related_logs = array();
    $query = $DB->query($sql);
    while ($row = $DB->fetch_array($query)) {
        $row['gid'] = intval($row['gid']);
        $row['title'] = htmlspecialchars($row['title']);
        $related_logs[] = $row;
    }
    $out = '';
    if (!empty($related_logs)) {
        foreach ($related_logs as $val) {
            $out .= '<li class="article-detail-youlike-list"><a class="article-detail-youlike-list-tit" href="' . Url::log($val['gid']) . "\">{$val['title']}</a></li>";
        }
    }
    if (!empty($value['content'])) {
        if ($related_inrss == 'y') {
            $abstract .= $out;
        }
    } else {
        echo $out;
    }
}?>
<?php function home_newlog($lognum){
    $db = MySql::getInstance();
    $sql = $db->query('SELECT * FROM ' . DB_PREFIX . 'blog inner join ' . DB_PREFIX . "sort WHERE hide='n' AND type='blog' AND top='n' AND sortid=sid order by date DESC limit $lognum");
    while ($row = $db->fetch_array($sql)) {
        $logpost = !empty($row['excerpt']) ? $row['excerpt'] : '' . $row['content'] . '';
        if (!empty($row['excerpt'])) {
            preg_match_all('/\\<img.*?src\\="(.*?)"[^>]*>/i', $row['excerpt'], $match);
            if (empty($match[0][0])) {
                preg_match_all('/\\<img.*?src\\="(.*?)"[^>]*>/i', $row['content'], $match);}
        } else {
            preg_match_all('/\\<img.*?src\\="(.*?)"[^>]*>/i', $row['content'], $match);}
		$thum_src = getThumbnail($row['gid']);
		$imgFileArray = glob("content/templates/static/img/random/*.*");
		$imgsrc = preg_match_all("|<img[^>]+src=\"([^>\"]+)\"?[^>]*>|is", $row['content'], $img);
		$imgsrc = !empty($img[1]) ? $img[1][0] : ''; 
        $date = gmdate('Y年m月d日', $row['date']);
        $content = strip_tags($logpost, '');
        $content = mb_substr($content, 0, 150, 'utf-8');
        $comment = $row['comnum'] != 0 ? '' . $row['comnum'] . '' : '0';
        $gid = $row['gid'];
        $tag = $db->query('SELECT * FROM ' . DB_PREFIX . "tag WHERE gid LIKE '%,{$gid},%'");?>
       <?php if($thum_src) :?> 
	   <?php $img = $thum_src;?>
		<?php elseif ($imgsrc) : ?>
       <?php $img = $imgsrc;?>
		<?php else :?>
        <?php $img = BLOG_URL. $imgFileArray[array_rand($imgFileArray)]; ?>
        <?php endif;?>
       <?php $out .= '
			<article class="excerpt">
				<a class="focus" href="'.Url::log($row['gid']) . '">
				<img src="'.$img.'" class="thumb" height="155" width="224">
				</a>
				<header>
					<a class="cat" href="'.Url::sort($row['sortid']).'" ">
						'.$row['sortname'].'
					</a> 
				<h2><a href="'.Url::log($row['gid']).'" title="' . $row['title'] . '">
					' . $row['title'] . '</a></h2>
				</header>
					<p class="meta">
						<time><i class="icon-calendar"></i> '.$date.'</time>
						<span class="pv">
						<i class="icon-eye-open"></i> 阅读(' . $row['views'] . ')
						</span>
						<i class="icon-comment"></i> 评论(' . $row['comnum'] . ')</p>
						<p class="note">' . $content . '...</p>
			</article>';}
    echo $out;
}?>

<?php function convertip($ip) {$dat_path = EMLOG_ROOT.'./content/templates/Jcms/ip.dat';
if(!$fd = @fopen($dat_path, 'rb')){ return 'IP数据库文件无法访问！';
} $ip = explode('.', $ip);
$ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3];
$DataBegin = fread($fd, 4);
$DataEnd = fread($fd, 4);
$ipbegin = implode('', unpack('L', $DataBegin));
if($ipbegin < 0) $ipbegin += pow(2, 32);
$ipend = implode('', unpack('L', $DataEnd));
if($ipend < 0) $ipend += pow(2, 32);
$ipAllNum = ($ipend - $ipbegin) / 7 + 1;
$BeginNum = 0;
$EndNum = $ipAllNum;
while($ip1num>$ipNum || $ip2num<$ipNum) { $Middle= intval(($EndNum + $BeginNum) / 2);
fseek($fd, $ipbegin + 7 * $Middle);
$ipData1 = fread($fd, 4);
if(strlen($ipData1) < 4) { fclose($fd);
return 'erro！';
} $ip1num = implode('', unpack('L', $ipData1));
if($ip1num < 0) $ip1num += pow(2, 32);
if($ip1num > $ipNum) { $EndNum = $Middle;
continue;
} $DataSeek = fread($fd, 3);
if(strlen($DataSeek) < 3) { fclose($fd);
return 'erro！';
}$DataSeek = implode('', unpack('L', $DataSeek.chr(0)));
fseek($fd, $DataSeek);
$ipData2 = fread($fd, 4);
if(strlen($ipData2) < 4) {fclose($fd);
return 'erro！';
} $ip2num = implode('', unpack('L', $ipData2));
if($ip2num < 0) $ip2num += pow(2, 32);
if($ip2num < $ipNum) { if($Middle == $BeginNum) { fclose($fd);
return '未知';
} $BeginNum = $Middle;
}   } $ipFlag = fread($fd, 1);
if($ipFlag == chr(1)) { $ipSeek = fread($fd, 3);
if(strlen($ipSeek) < 3) {fclose($fd);
return 'erro！';
} $ipSeek = implode('', unpack('L', $ipSeek.chr(0)));
fseek($fd, $ipSeek);
$ipFlag = fread($fd, 1);
} if($ipFlag == chr(2)) { $AddrSeek = fread($fd, 3);
if(strlen($AddrSeek) < 3) { fclose($fd);
return 'erro！';
} $ipFlag = fread($fd, 1);
if($ipFlag == chr(2)) {$AddrSeek2 = fread($fd, 3);
if(strlen($AddrSeek2) < 3) { fclose($fd);
return 'erro！';
} $AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));
fseek($fd, $AddrSeek2);
} else {fseek($fd, -1, SEEK_CUR);
} while(($char = fread($fd, 1)) != chr(0)) $ipAddr2 .= $char;
$AddrSeek = implode('', unpack('L', $AddrSeek.chr(0)));
fseek($fd, $AddrSeek);
while(($char = fread($fd, 1)) != chr(0)) $ipAddr1 .= $char;
} else {fseek($fd, -1, SEEK_CUR);
while(($char = fread($fd, 1)) != chr(0)) $ipAddr1 .= $char;
$ipFlag = fread($fd, 1);
if($ipFlag == chr(2)) { $AddrSeek2 = fread($fd, 3);
if(strlen($AddrSeek2) < 3) {fclose($fd);
return 'erro！';
} $AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));
fseek($fd, $AddrSeek2);
} else { fseek($fd, -1, SEEK_CUR);
}while(($char = fread($fd, 1)) != chr(0)){ $ipAddr2 .= $char;
}   }fclose($fd);
if(preg_match('/http/i', $ipAddr2)) {$ipAddr2 = '';
}$ipaddr = "$ipAddr1 $ipAddr2";
$ipaddr = preg_replace('/CZ88.Net/is', '', $ipaddr);
$ipaddr = preg_replace('/^s*/is', '', $ipaddr);
$ipaddr = preg_replace('/s*$/is', '', $ipaddr);
if(preg_match('/http/i', $ipaddr) || $ipaddr == '') { $ipaddr = '未知';
} $ipaddr = iconv('gbk', 'utf-8//IGNORE', $ipaddr);
if( $ipaddr != '  ' ) return $ipaddr;
else $ipaddr = '评论者来自黑洞，无法获取其所在星球!';
return $ipaddr;
} ?>
<?php function blog_content($log_content,$msg='纳尼，博主居然没在这写内容？？'){
	if(ROLE == ROLE_VISITOR){
	$log_content=preg_replace('/\[box dl\]*(.*?)(\[\/box)?\]/e', '"<div class=\"j_error\"><a title=\"此处内容已隐藏\" style=\"color:#f00\"><i class=\"icon-eye-close\" ></i></a> 此处内容已隐藏，<a href=\"javascript:;\" class=\"signin-loader\">登录</a>后即可查看。没有账号？那就<a class=\"signup-loader\" href=\"javascript:;\">注册</a>吧!!!</div>"',$log_content);
	}else{
	$log_content=preg_replace('/\[box dl\]*(.*?)(\[\/box)?\]/e', '"<div class=\"j_dl\"><a title=\"这是隐藏后的内容\" style=\"color:#eee\"><i class=\"icon-eye-open\"></i></a> $1</div>"',$log_content);}
	$jdl = array('[box dl]','[box error]','[box notice]', '[box tips]', '[box warn]', '[/box]');
	$jzh = array('<div class="j_dl">', '<div class="j_error">', '<div class="j_notice">', '<div class="j_tips">', '<div class="j_warn">', '</div>');
	$replace = str_replace($jdl, $jzh, $log_content);
	echo ($replace?$replace:'<div class="j_error">'.$msg.'</div>');
	}?>
    
    
<?php //站点头部
function blog_head(){?>
	<header class="header">
<div id="loading"><div style="width:20%;"></div></div>
<div class="container">
	<div class="logo">
		<a href="<?php echo BLOG_URL;?>" title="<?php echo $bloginfo;?>">
		<?php echo $blogname;?></a>
	</div>
	<ul class="navbar"><?php blog_navi();?>
	</ul>
	<div class="topbar-user">
		<div class="user-signin">
        <?php if(ROLE == 'admin' || ROLE == 'writer'): ?>
        <?php global $CACHE;$user_cache = $CACHE->readCache('user');$name = $user_cache[$author]['mail'] != '' ? "".$user_cache[$author]['name']."" : $user_cache[1]['name'];?>
        <a class="user-welcome" title="进入用户中心" href="<?php echo BLOG_URL;?>admin">
        <?php if($user_cache[$author]['photo']['src']):?><?php global $CACHE;$user_cache = $CACHE->readCache('user'); if (!empty($user_cache[$author]['photo']['src'])): ?>
      <img data-src="<?php echo BLOG_URL.$user_cache[$author]['photo']['src']; ?>" class="avatar avatar-50 photo" src="<?php echo TEMPLATE_URL;?>img/avatar-default.png" height="50" width="50">
	  <?php endif; ?>
	  <?php else:?><img data-src="<?php echo getGravatar($user_cache[$author]['mail']); ?>" class="avatar avatar-50 photo" height="50" width="50" src="<?php echo TEMPLATE_URL;?>img/avatar-default.png"><?php endif; ?>
        <span><?php echo $name;?></span></a>
        <?php else:?>
			<a class="btn btn-primary btn-sm signin-loader" href="javascript:;"><i class="icon-user"></i> 登录</a><a class="btn btn-default btn-sm signup-loader" href="javascript:;">注册</a>
        <?php endif;?>
		</div>
	</div>
	<form class="searchform" name="keyform" method="get" action="<?php echo BLOG_URL;?>">
		<input class="search-input" name="keyword" type="text" placeholder="输入关键字搜索"><button class="search-btn" type="submit"><i class="icon-search icon-large"></i></button>
	</form>
	<div class="m-icon-nav"><i class="icon-windows"></i>
	</div>
</div>
</header>
<?php }?>
